package com.hq.ims.platform.controller;

import com.hq.ims.data.annotation.UserOperationMonitor;
import com.hq.ims.data.entityenum.EnumBusinessRepeatType;
import com.hq.ims.data.service.*;
import com.hq.ims.data.utils.LocalConstant;
import com.hq.ims.data.vo.*;
import com.hq.ims.platform.busservice.PlatformBusiInfoService;
import com.hq.mybatis.base.page.RequestPage;
import com.hq.mybatis.base.page.ReturnPage;
import com.hq.utils.vo.ReturnVo;
import com.hq.web.annotations.GetJsonValue;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yinzhangxiao
 * @date 2024/10/25 14:35
 * @ClassName PlatformBusiInfoController
 **/
@Api(tags = "经营信息管理")
@RestController
@RequestMapping(LocalConstant.SYS_TYPE_PLATFORM_URL_PREFIX + "/sys/busiInfo")
public class PlatformBusiInfoController {

    @Resource
    private PlatformBusiInfoService platformBusiInfoService;
    @Resource
    private BaseBusiRepeatTypeCountDataService baseBusiRepeatTypeCountDataService;
    @Resource
    private BaseBusiChangeTimeRecordService baseBusiChangeTimeRecordService;
    @Resource
    private BaseBusiHistoryService baseBusiHistoryService;
    @Resource
    private BaseBusiChangeService baseBusiChangeService;
    @Resource
    private BaseBusiInfoService baseBusiInfoService;


    @ApiOperation(value = "经营信息分页", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getPage", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<ReturnPage> getPage(
            @RequestBody RequestPage page,
            @RequestBody BusiInfoMapstruct.PageSearchVo searchVo
    ) {
        baseBusiInfoService.getByPage(page, searchVo);
        return ReturnVo.buildSuccess(page.getReturnPage());
    }

    @ApiOperation(value = "审核经营信息", consumes = MediaType.APPLICATION_JSON_VALUE)
    @UserOperationMonitor
    @ApiImplicitParams({})
    @PostMapping(value = "/audit", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<Boolean> audit(@RequestBody BusiInfoMapstruct.SaveVo vo) {
        platformBusiInfoService.audit(vo);
        return ReturnVo.buildSuccess(true);
    }

    @ApiOperation(value = "经营信息详情", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<BusiInfoMapstruct.BusiInfoVo> getData(@GetJsonValue(zh = "数据ID") String busiInfoId) {
        return ReturnVo.buildSuccess(baseBusiInfoService.getDetailVo(busiInfoId));
    }

    @ApiOperation(value = "查看源信息", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getRootData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<BusiInfoMapstruct.BusiInfoVo> getRootData(@GetJsonValue(zh = "数据ID") String parentId) {
        return ReturnVo.buildSuccess(platformBusiInfoService.getRootData(parentId));
    }

    @ApiOperation(value = "查看重复信息", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
    })
    @PostMapping(value = "/getRepeatData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<ReturnPage> getRepeatData(
            @RequestBody RequestPage page,
            @GetJsonValue(zh = "重复类型") EnumBusinessRepeatType repeatType,
            @GetJsonValue(zh = "数据ID") String busiInfoId
    ) {
        baseBusiRepeatTypeCountDataService.getRepeatData(page,repeatType, busiInfoId);
        return  ReturnVo.buildSuccess(page.getReturnPage());
    }

    @ApiOperation(value = "查看变更历史记录", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getChangeData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<BusiChangeTimeRecordMapstruct.BusiChangeTimeRecordVo>> getChangeData(
            @GetJsonValue(zh = "数据ID") String busiInfoId
    ) {
        return ReturnVo.buildSuccess(baseBusiChangeTimeRecordService.getChangeData(busiInfoId));
    }


    @ApiOperation(value = "查看经营历史信息", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getHistoryData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<BusiHistoryMapstruct.BusiHistoryVo> getHistoryData(
            @GetJsonValue(zh = "数据ID") String busiHistoryId
    ) {
        return ReturnVo.buildSuccess(baseBusiHistoryService.getDetailVo(busiHistoryId));
    }

    @ApiOperation(value = "经营信息接收情况", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getReceiveData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<BusiIndustryAssignMapstruct.BusiIndustryAssignVo>> getReceiveData(
            @GetJsonValue(zh = "数据ID") String busiInfoId
    ) {
        return ReturnVo.buildSuccess(baseBusiInfoService.getReceiveData(busiInfoId));
    }

    @ApiOperation(value = "经营信息反馈情况", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getFeedBackData", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<List<BusiIndustryAssignMapstruct.BusiIndustryAssignVo>> getFeedBackData(
            @GetJsonValue(zh = "数据ID") String busiInfoId
    ) {
        return ReturnVo.buildSuccess(baseBusiInfoService.getFeedBackData(busiInfoId));
    }

    @ApiOperation(value = "经营信息变更记录", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({})
    @PostMapping(value = "/getChangePage", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ReturnVo<ReturnPage> getChangePage(
            @RequestBody RequestPage page,
            @RequestBody BusiChangeMapstruct.PageSearchVo searchVo
    ) {
        if (StringUtils.isBlank(searchVo.getBusiInfoId())){
            throw new RuntimeException("业务参数错误！");
        }
        baseBusiChangeService.getByPage(page,searchVo);
        return ReturnVo.buildSuccess(page.getReturnPage());
    }
}
